package cn.edu.java.collection;

import java.util.LinkedHashMap;
import java.util.Map;

public class LinkedHashMapDemo {
    public static void main(String[] args) {
        // 创建一个 LinkedHashMap 实例，按插入顺序保持元素的顺序
        LinkedHashMap<String, Integer> scores = new LinkedHashMap<>();

        // 添加元素到 LinkedHashMap
        scores.put("Alice", 85);
        scores.put("Bob", 90);
        scores.put("Charlie", 78);
        scores.put("David", 95);

        // 遍历 LinkedHashMap，按插入顺序输出元素
        for (Map.Entry<String, Integer> entry : scores.entrySet()) {
            String name = entry.getKey();
            int score = entry.getValue();
            System.out.println(name + ": " + score);
        }
    }
}

